package me.zhengjie.minbearwcs.controller.common;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.minbearwcs.entity.DTO.response.RespWithObject;
import me.zhengjie.minbearwcs.entity.DTO.transfer.Tuple;
import me.zhengjie.minbearwcs.entity.PO.config.HttpConfig;
import me.zhengjie.minbearwcs.serivce.common.MinBearService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
@RequiredArgsConstructor
public class MinBearController {

    private final MinBearService minBearService;

    @GetMapping("/http/tusk/config")
    public RespWithObject<HttpConfig> getTuskHttpConig(){
        Tuple<HttpConfig> tuskHttpConig = minBearService.getTuskHttpConig();
        return new RespWithObject<HttpConfig>()
                .code(tuskHttpConig.success)
                .data(tuskHttpConig.value);
    }

    @PostMapping("/http/tusk/config")
    public RespWithObject<HttpConfig> updateTuskHttpConig(@RequestBody Map<String,String> infoReq){
        String httpUrl = infoReq.get("httpUrl");
        Tuple<HttpConfig> tuskHttpConig = minBearService.updateTuskHttpConig(httpUrl);
        return new RespWithObject<HttpConfig>()
                .code(tuskHttpConig.success);
    }


    @GetMapping("/http/wms/config")
    public RespWithObject<HttpConfig> getWmsHttpConig(){
        Tuple<HttpConfig> tuskHttpConig = minBearService.getWmsHttpConig();
        return new RespWithObject<HttpConfig>()
                .code(tuskHttpConig.success)
                .data(tuskHttpConig.value);
    }


    @PostMapping("/http/wms/config")
    public RespWithObject<HttpConfig> updateWmsHttpConig(@RequestBody Map<String,String> infoReq){
        String httpUrl = infoReq.get("httpUrl");
        Tuple<HttpConfig> wmsHttpConig = minBearService.updateWmsHttpConig(httpUrl);
        return new RespWithObject<HttpConfig>()
                .code(wmsHttpConig.success);
    }

}
